;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "Igender-criterion.lisp")
(require "Ilist.lisp")

(module Mgender-criterion
  
(import Ilist)

  (defconst *FEMALE* "f")
(defconst *MALE* "m")
(defconst *GENDER-LIST* (list *FEMALE* *MALE*))
(defconst *UPPER-BOUND-FOR-LOW-GENDER-PERCENTAGE* 0.33)
(defconst *NO-SUFFICIENT-LOW-PERCENTAGE-GENDER* "N/A")

(defconst *UNKNOWN-ERROR* "UNKNOWN ERROR!!!")
  

(defun get-team-low-percentage-gender
  (list-of-team-member-genders num-of-members)
  (if (consp list-of-team-member-genders)
      (let ((female-percentage
            (/ (occurrences-equal *FEMALE* list-of-team-member-genders)
               num-of-members))
            (male-percentage
             (/ (occurrences-equal *MALE* list-of-team-member-genders)
                num-of-members)))
      (cond ((< female-percentage *UPPER-BOUND-FOR-LOW-GENDER-PERCENTAGE*)
             *FEMALE*)
            ((< male-percentage *UPPER-BOUND-FOR-LOW-GENDER-PERCENTAGE*)
             *MALE*)
            (t
            *NO-SUFFICIENT-LOW-PERCENTAGE-GENDER*)))
      *UNKNOWN-ERROR*))

(defun convert-gender
  (gender low-percentage-gender)
  (if (string-equal gender low-percentage-gender)
      1
      0))
       
(defun get-list-of-team-member-gender-converted
  (list-of-team-member-genders low-percentage-gender)
  (if (consp list-of-team-member-genders)
      (cons (convert-gender
             (car list-of-team-member-genders)
             low-percentage-gender)
            (get-list-of-team-member-gender-converted
             (cdr list-of-team-member-genders)
             low-percentage-gender))
      nil))

(defun calculate-team-gender-score
  (list-of-all-team-member-data-by-criterion num-of-members gender-weight)
   (if (not (or (endp list-of-all-team-member-data-by-criterion)
                (zerop gender-weight)))
      (let* ((list-of-team-member-gender
              (cadr list-of-all-team-member-data-by-criterion))
             (low-percentage-gender
              (get-team-low-percentage-gender list-of-team-member-gender
                                              num-of-members)))
        (if (equal low-percentage-gender
                   *NO-SUFFICIENT-LOW-PERCENTAGE-GENDER*)
            gender-weight
            (let* ((list-of-team-member-gender-converted
                    (get-list-of-team-member-gender-converted list-of-team-member-gender
                                                              low-percentage-gender))
                   (sum-gender
                    (sumlist list-of-team-member-gender-converted))
                   (heuristic-result
                    (cond ((>= sum-gender 2) 1)
                          ((= sum-gender 1) -1)
                          ((= sum-gender 0) 0))))
              (* heuristic-result gender-weight))))
      0))

  (export Igender-criterion))

